﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogisticsBLL;
using Model;

namespace WebLosgic.Carress
{
    public partial class UpdateCarrier : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int carID=Convert.ToInt32(Request.QueryString["ID"]);
                if (carID != 0)
                {
                    GetBind(carID);
                }
                else
                {
                    Response.Redirect("CarrierManage.aspx");
                }
                ViewState["retu"] = Request.UrlReferrer.ToString();
            }
        }

        protected void GetBind(int carsID)
        {
            CarriessCyBLL cyb = new CarriessCyBLL();
            Carriers cars = cyb.Carrideail(carsID);
            TxtSendAddress.Text = cars.SendAddress;
            TxtFK_ReceiveAddress.Text = cars.ReceiveAddress;
            TexReceiveCompany.Text = cars.ReceiveCompany;
            TxtSendCompany.Text = cars.SendCompany;
            TxtReceivePhone.Text = cars.ReceivePhone;
            TxtSendPhone.Text = cars.SendPhone;
            TxtSendLinkman.Text = cars.SendLinkman;
            TexReceiveLinkman.Text = cars.ReceiveLinkman;
            TxtOtherCost.Text = cars.OtherCost;
            TexInsuranceCost.Text = cars.InsuranceCost;
            TexTransportCost.Text = cars.TransportCost;
        }

        protected void BtnInsert_Click(object sender, EventArgs e)
        {
            int carID = Convert.ToInt32(Request.QueryString["ID"]);
            CarriessCyBLL cyb = new CarriessCyBLL();
            Carriers cars = new Carriers();
            cars.SendAddress=TxtSendAddress.Text;
            cars.ReceiveAddress=TxtFK_ReceiveAddress.Text;
            cars.ReceiveCompany=TexReceiveCompany.Text;
            cars.SendCompany=TxtSendCompany.Text;
            cars.ReceivePhone=TxtReceivePhone.Text;
            cars.SendPhone=TxtSendPhone.Text;
            cars.SendLinkman=TxtSendLinkman.Text;
            cars.ReceiveLinkman=TexReceiveLinkman.Text;
            cars.OtherCost=TxtOtherCost.Text;
            cars.InsuranceCost=TexInsuranceCost.Text;
            cars.TransportCost=TexTransportCost.Text;
            cars.CarriesID = carID.ToString();
            int reult = cyb.UpdateCaries(cars);
            string name = Session["names"].ToString();
            string Behavor = "" + name + ": 修改车辆信息";
            int TypeId = 16;
            int UserID = Convert.ToInt32(Session["UserIDs"]);
            string Parameters = @"" + TexReceiveLinkman.Text + "," + TxtSendAddress.Text + "";
            string ProcName = "p_Update_Carriers";
            HttpRequest request = HttpContext.Current.Request;
            string IP = "192.168.0.1";
            int IsExcePion = 0;
            if (reult>0)
            {
                IsExcePion = 0;
                int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
                if (a > 0)
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('修改成功'); location.href='CarrierManage.aspx'", true);
                }
                
            }
            else
            {
                IsExcePion = 1;
                int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
                if (a > 0)
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('修改失败')", true);
                }
                
            }
        }

        protected void BtninstCheng_Click(object sender, EventArgs e)
        {
            Response.Redirect(ViewState["retu"].ToString());
        }
    }
}